import JSON5 from 'json5';

export const COLOR_CASES = [
    {
        name: '默认',
        value: 'default',
        colors: [
            '#1E90FF',
            '#90EE90',
            '#00CED1',
            '#E2BD84',
            '#7A90E0',
            '#3BA272',
            '#2BE7FF',
            '#0A8ADA',
            '#FFD700'
        ]
    },
    {
        name: '复古',
        value: 'retro',
        colors: [
            '#0780cf',
            '#765005',
            '#fa6d1d',
            '#0e2c82',
            '#b6b51f',
            '#da1f18',
            '#701866',
            '#f47a75',
            '#009db2'
        ]
    },
    {
        name: '淡雅',
        value: 'elegant',
        colors: [
            '#95a2ff',
            '#fa8080',
            '#ffc076',
            '#fae768',
            '#87e885',
            '#3cb9fc',
            '#73abf5',
            '#cb9bff',
            '#434348'
        ]
    },
    {
        name: '未来',
        value: 'future',
        colors: [
            '#63b2ee',
            '#76da91',
            '#f8cb7f',
            '#f89588',
            '#7cd6cf',
            '#9192ab',
            '#7898e1',
            '#efa666',
            '#eddd86'
        ]
    },
    {
        name: '渐变',
        value: 'gradual',
        colors: [
            '#71ae46',
            '#96b744',
            '#c4cc38',
            '#ebe12a',
            '#eab026',
            '#e3852b',
            '#d85d2a',
            '#ce2626',
            '#ac2026'
        ]
    },
    {
        name: '简洁',
        value: 'simple',
        colors: [
            '#929fff',
            '#9de0ff',
            '#ffa897',
            '#af87fe',
            '#7dc3fe',
            '#bb60b2',
            '#433e7c',
            '#f47a75',
            '#009db2'
        ]
    },
    {
        name: '商务',
        value: 'business',
        colors: [
            '#194f97',
            '#555555',
            '#bd6b08',
            '#00686b',
            '#c82d31',
            '#625ba1',
            '#898989',
            '#9c9800',
            '#007f54'
        ]
    },
    {
        name: '柔和',
        value: 'gentle',
        colors: [
            '#5b9bd5',
            '#ed7d31',
            '#70ad47',
            '#ffc000',
            '#4472c4',
            '#91d024',
            '#b235e6',
            '#02ae75',
            '#5b9bd5'
        ]
    },
    {
        name: '科技',
        value: 'technology',
        colors: [
            '#05f8d6',
            '#0082fc',
            '#fdd845',
            '#22ed7c',
            '#09b0d3',
            '#1d27c9',
            '#f9e264',
            '#f47a75',
            '#009db2'
        ]
    },
    {
        name: '明亮',
        value: 'light',
        colors: [
            '#884898',
            '#808080',
            '#82ae46',
            '#00a3af',
            '#ef8b07',
            '#007bbb',
            '#9d775f',
            '#fae800',
            '#5f9b3c'
        ]
    },
    {
        name: '经典',
        value: 'classical',
        colors: [
            '#007bbb',
            '#ffdb4f',
            '#dd4b4b',
            '#2ca9e1',
            '#ef8b07',
            '#4a488e',
            '#82ae46',
            '#dd4b4b',
            '#bb9581'
        ]
    },
    {
        name: '清新',
        value: 'fresh',
        colors: [
            '#5f9b3c',
            '#75c24b',
            '#83d65f',
            '#aacf53',
            '#c7dc68',
            '#d8e698',
            '#e0ebaf',
            '#bbc8e6',
            '#e5e5e5'
        ]
    },
    {
        name: '活力',
        value: 'energy',
        colors: [
            '#ef8b07',
            '#2a83a2',
            '#f07474',
            '#c55784',
            '#274a78',
            '#7058a3',
            '#0095d9',
            '#75c24b',
            '#808080'
        ]
    },
    {
        name: '火红',
        value: 'red',
        colors: [
            '#ff0000',
            '#ef8b07',
            '#4c6cb3',
            '#f8e944',
            '#69821b',
            '#9c5ec3',
            '#00ccdf',
            '#f07474',
            '#bb9581'
        ]
    },
    {
        name: '轻快',
        value: 'fast',
        colors: [
            '#fae800',
            '#00c039',
            '#0482dc',
            '#bb9581',
            '#ff7701',
            '#9c5ec3',
            '#00ccdf',
            '#00c039',
            '#ff7701'
        ]
    },
    {
        name: '灵动',
        value: 'spiritual',
        colors: [
            '#00a3af',
            '#4da798',
            '#57baaa',
            '#62d0bd',
            '#6ee4d0',
            '#86e7d6',
            '#aeede1',
            '#bde1e6',
            '#e5e5e5'
        ]
    }
];

export const PREDEFINE_COLORS = [
    '#FF4500',
    '#FF8C00',
    '#FFD700',
    '#71AE46',
    '#00CED1',
    '#1E90FF',
    '#C71585',
    '#999999',
    '#000000',
    '#FFFFFF'
];

export const parseColors = (scheme) => {
    try {
        const colorScheme = JSON5.parse(scheme || '{}');
        if (colorScheme.colors && colorScheme.colors.length > 0) {
            return colorScheme.colors;
        } else if (colorScheme.name) {
            const item = COLOR_CASES.find(ele => ele.value === colorScheme.name);
            if (item) {
                return item.colors;
            }
        }
        return COLOR_CASES[0].colors;
    } catch (e) {
        return COLOR_CASES[0].colors;
    }
};